#pragma once

#include <cftc/reflect/object.h>
#include <cftf/meta/table.h>

namespace mt
{
	class Item : public cftc::reflect::Object, public cftf::meta::Table<Item, unsigned int>
	{
		CFT_DECLARE_REFLECT_CLASS();
	public:
		struct ItemSetEffect
		{
			unsigned int setid = 0;
			unsigned int item_count = 0;
			std::vector<const dbc::SpellEntry*> spells; //8
		};
		struct _ItemStat : public cftc::reflect::Object
		{
			CFT_DECLARE_REFLECT_CLASS();
			unsigned int ItemStatType = 0;
			int ItemStatValue = 0;
		};
		struct _Damage : public cftc::reflect::Object
		{
			CFT_DECLARE_REFLECT_CLASS();
			float DamageMin = 0;
			float DamageMax = 0;
			unsigned int DamageType = 0;                                     // id from Resistances.dbc
		};
		struct _Spell : public cftc::reflect::Object
		{
			CFT_DECLARE_REFLECT_CLASS();
		public:
			unsigned int SpellId = 0;                                         // id from Spell.dbc
			unsigned int SpellTrigger = 0;
			int SpellCharges = 0;
			float SpellPPMRate = 0;
			int SpellCooldown = 0;
			unsigned int SpellCategory = 0;                                   // id from SpellCategory.dbc
			int SpellCategoryCooldown = 0;
		};

		enum ItemClass
		{
			ITEM_CLASS_CONSUMABLE = 0,
			ITEM_CLASS_CONTAINER = 1,
			ITEM_CLASS_WEAPON = 2,
			ITEM_CLASS_RESERVED_1 = 3,
			ITEM_CLASS_ARMOR = 4,
			ITEM_CLASS_REAGENT = 5,
			ITEM_CLASS_PROJECTILE = 6,
			ITEM_CLASS_TRADE_GOODS = 7,
			ITEM_CLASS_RESERVED_2 = 8,
			ITEM_CLASS_RECIPE = 9,
			ITEM_CLASS_RESERVED_3 = 10,
			ITEM_CLASS_QUIVER = 11,
			ITEM_CLASS_QUEST = 12,
			ITEM_CLASS_KEY = 13,
			ITEM_CLASS_RESERVED_4 = 14,
			ITEM_CLASS_MISC = 15
		};

#define MAX_ITEM_CLASS                            16

		enum ItemSpelltriggerType
		{
			ITEM_SPELLTRIGGER_ON_USE = 0,                  // use after equip cooldown
			ITEM_SPELLTRIGGER_ON_EQUIP = 1,
			ITEM_SPELLTRIGGER_CHANCE_ON_HIT = 2,
			ITEM_SPELLTRIGGER_SOULSTONE = 4,
			/*
			 * ItemSpelltriggerType 5 might have changed on 2.4.3/3.0.3: Such auras
			 * will be applied on item pickup and removed on item loss - maybe on the
			 * other hand the item is destroyed if the aura is removed ("removed on
			 * death" of spell 57348 makes me think so)
			 */
			ITEM_SPELLTRIGGER_ON_NO_DELAY_USE = 5,                  // no equip cooldown
		};

#define MAX_ITEM_SPELLTRIGGER           6
	public:
		unsigned int entry = 0;
		unsigned int class_ = 0;
		std::string name;
		unsigned int displayid = 0;
		unsigned int Quality = 0;
		unsigned int Flags = 0;
		unsigned int BuyCount = 0;
		unsigned int BuyPrice = 0;
		unsigned int SellPrice = 0;
		unsigned int InventoryType = 0;
		unsigned int AllowableClass = 0;
		unsigned int AllowableRace = 0;
		unsigned int ItemLevel = 0;
		unsigned int RequiredLevel = 0;
		unsigned int RequiredSkill = 0;
		unsigned int RequiredSkillRank = 0;
		unsigned int requiredspell = 0;
		unsigned int requiredhonorrank = 0;
		unsigned int RequiredCityRank = 0;
		unsigned int RequiredReputationFaction = 0;
		unsigned int RequiredReputationRank = 0;
		unsigned int maxcount = 0;
		unsigned int stackable = 0;
		unsigned int ContainerSlots = 0;

		unsigned int armor = 0;
		unsigned int holy_res = 0;
		unsigned int fire_res = 0;
		unsigned int nature_res = 0;
		unsigned int frost_res = 0;
		unsigned int shadow_res = 0;
		unsigned int arcane_res = 0;
		unsigned int delay = 0;
		unsigned int ammo_type = 0;
		float RangedModRange = 0;
		unsigned int bonding = 0;
		std::string description;
		unsigned int PageText = 0;
		unsigned int LanguageID = 0;
		unsigned int PageMaterial = 0;
		unsigned int startquest =  0;
		unsigned int lockid = 0;
		int Material = 0;
		unsigned int sheath = 0;
		unsigned int RandomProperty = 0;
		unsigned int block = 0;
		unsigned int itemset = 0;
		unsigned int MaxDurability = 0;
		unsigned int area = 0;
		unsigned int Map = 0;
		int BagFamily = 0;
		unsigned int DisenchantID = 0;
		unsigned int FoodType = 0;
		unsigned int minMoneyLoot = 0;
		unsigned int maxMoneyLoot = 0;
		unsigned int Duration = 0;
		unsigned int ExtraFlags = 0;

		void MetaInstanceInit1();

		std::vector<std::shared_ptr<_ItemStat>> ItemStat;
		std::vector<std::shared_ptr<_Damage>> Damage;
		std::vector<std::shared_ptr<_Spell>> Spells;
	};

}